﻿import mx.utils.Delegate;

/**********************/
/*
 *  cRobo
 *
 *  Class for automated testing
*/
/**********************/

class com.unifiedfield.cRobo {
	private var m_sNextJumpToLabel:String;
	private var m_iCurrentIntervalId:Number;
	private var m_iLastMain_1_Select:Number;
	private var m_iLastMain_2_Select:Number;
	private var m_sStationName:String;
	
	public function cRobo( ) 
		{
		m_iCurrentIntervalId = 0;
		m_sNextJumpToLabel = null;
		m_iLastMain_1_Select = 1;
		m_iLastMain_2_Select = 2;   // Expects 2-4
		}
		
public function SetStationName( sName:String ):Void
    {
		m_sStationName = sName;
		}

	/**********************/
	/*
	 *  waitAnyTouch()
	 *
	 *  Waits for given time and then jumps to given Label
	*/
	/**********************/
	public function waitAnyTouch(iWaitMs:Number, sNextLabel:String):Void 
		{
		/* Set location we will jump to when time runs out. */
		m_sNextJumpToLabel = sNextLabel;
		/* Clear out any old timer. */
		clearInterval( m_iCurrentIntervalId );
		/* Start this timer. */
		m_iCurrentIntervalId = setInterval(this, "handleAnyTouchTimer", iWaitMs);
		} // End waitAnyTouch()
	
	/**********************/
	/*
	 *  handleAnyTouchTimer()
	 *
	*/
	/**********************/
	private function handleAnyTouchTimer():Void
	  {
		/* Clear the timer. */
		clearInterval( m_iCurrentIntervalId );
		/* And jump. */
		if( m_sNextJumpToLabel != null )
		  {
			goToAndStop( m_sNextJumpToLabel );			
			}
		} // End handleAnyTouchTimer()
	
	/**********************/
	/*
	 *  mainMenuLevel_1()
	 *
	 *  Waits for given time and then sets a global and calls a function
	*/
	/**********************/
	private function mainMenuLevel_1( iWaitMs:Number ): Void
	  {
		
		trace( "Start robo menu 1. ");
			
		m_iLastMain_1_Select++;
		
		if( m_iLastMain_1_Select > 4 )
		  {
			m_iLastMain_1_Select = 1;
			}
		
		_root.SHOW = m_iLastMain_1_Select;
		
		/* Clear out any old timer. */
		clearInterval( m_iCurrentIntervalId );
		/* Start this timer. */
		m_iCurrentIntervalId = setInterval(this, "handleMenu_1_Timer", iWaitMs);
			
		}  // End mainMenuLevel_1()
		
	/**********************/
	/*
	 *  handleMenu_1_Timer()
	 *
	*/
	/**********************/
	private function handleMenu_1_Timer():Void
	  {
		/* Clear the timer. */
		clearInterval( m_iCurrentIntervalId );
		/* And start the second menu. */
		_root.menu.play();
		trace( "Did menu 1 menu.play. ");
		} // End handleMenu_1_Timer()
	
	/**********************/
	/*
	 *  mainMenuLevel_2()
	 *
	 *  Waits for given time and then sets a global and calls a function
	*/
	/**********************/
	private function mainMenuLevel_2( iWaitMs:Number ): Void
	  {
		
		trace( "Start robo menu 2. ");
			
		m_iLastMain_2_Select++;
		
		if( m_iLastMain_2_Select > 4 )
		  {
			m_iLastMain_2_Select = 2;
			}
		
		trace("Menu 2 = "+m_iLastMain_2_Select);

		/* Clear out any old timer. */
		clearInterval( m_iCurrentIntervalId );
		/* Start this timer. */
		m_iCurrentIntervalId = setInterval(this, "handleMenu_2_Timer", iWaitMs);
			
		}  // End mainMenuLevel_2()
	
	/**********************/
	/*
	 *  handleMenu_2_Timer()
	 *
	*/
	/**********************/
	private function handleMenu_2_Timer():Void
	  {
		/* Clear the timer. */
		clearInterval( m_iCurrentIntervalId );
		
		/* Set the globals. */
		_root.picked[0] = m_iLastMain_1_Select;
		_root.picked[1] = m_iLastMain_2_Select;		
		
		trace("Menu 1 = "+m_iLastMain_1_Select+"Menu 2 = "+m_iLastMain_2_Select);
		
		/* And start the second menu. */
		_root.nextFrame();

		trace( "Did menu 2. ");
		} // End handleMenu_2_Timer()

	/**********************/
	/*
	 *  waitKeyboardPlay()
	 *
	 *  Waits for given time and then does a play
	 *  Fills "email" with a random value.
	*/
	/**********************/
	private function waitKeyboardPlay( iWaitMs:Number ): Void
	  {
		
		trace( "Start wait keyboard play. ");
		
		/* Create an email address. */
		var dNow:Date = new Date();
		//var iDay:Number = dNow.getTime();
		//var sDay:String = iMs.toString();
		var sMs:String = String(dNow.getTime());
    _root.email = sMs+"@:"+m_sStationName+".com";
		_root.screen_email.infield.text=_root.email;

		/* Clear out any old timer. */
		clearInterval( m_iCurrentIntervalId );
		/* Start this timer. */
		m_iCurrentIntervalId = setInterval(this, "handleKeyboardWaitPlay_Timer", iWaitMs);
			
		}  // End waitKeyboardPlay()
	
	/**********************/
	/*
	 *  handleKeyboardWaitPlay_Timer()
	 *
	*/
	/**********************/
	private function handleKeyboardWaitPlay_Timer():Void
	  {
		trace( "Got keyboard timeout. ");
		/* Clear the timer. */
		clearInterval( m_iCurrentIntervalId );
		
		gotoAndPlay( 103 );

//		goToAndStop( "email" );			

		
		trace( "Finished wait keyboard play. ");
		} // End handleKeyboardWaitPlay_Timer()


	
		
		
	
	} // End class com.unifiedfield.cRobo()

		
		